﻿using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;

namespace MicroMVVM.Navigation
{
    internal class NavigationHelpers
    {
        /// <summary>
        /// Gets the parent element.
        /// </summary>
        /// <typeparam name="T">Parent type</typeparam>
        /// <param name="element">This dependency object</param>
        /// <returns></returns>
        public static object GetParent<T>(DependencyObject element)
        {
            if (element == null) return null;

            var parent = VisualTreeHelper.GetParent(element);

            if (parent == null) return null;

            if (parent is T) return parent;

            return GetParent<T>(parent);
        }
    }
}